home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-08-25 | 8.0 KB | 271 lines | [TEXT/CWIE] |
-
- #include "CTextEditorWindow.h"
- #include "CFileRefEditorWindow.h"
- #include "CSAMLauncherEditorWindow.h"
- #include "EditorUtilities.h"
-
- // Dialog panes
- const ResType kPanelTitleET = 'ptsE';
- const ResType kFirstHelpPicET = 'pihE';
- const ResType kEditMainTextB = 'emtB';
- const ResType kEditHelpTextB = 'ethB';
- const ResType kEmbedHelpTextRB = 'emhR';
- const ResType kFileHelpTextRB = 'sfhR';
- const ResType kRemoveB = 'rmvB';
- const ResType kEditAppFileRefB = 'eafB';
-
-
- // ---------------------------------------------------------------------------
- // • CEditorWindow
- // ---------------------------------------------------------------------------
- CEditorWindow::CEditorWindow( SInt16 inFileRefNum, SInt16 inPreferenceRsrcID, SInt16 inResListRsrcID )
- : StDialogHandler(200, NULL), mFileRefNum(inFileRefNum), mPreferenceRsrcID(inPreferenceRsrcID), mResListRsrcID(inResListRsrcID), mFlags(0), mStringListRsrcID(0), mMainTextRsrcID(0), mHelpTextRsrcID(0), mAppFileRefRsrcID(0)
-
- {
-
- if( mPreferenceRsrcID == 0 ) {
- SInt16** theIDHandle = (SInt16**) GetIndResource( 'paul', 1 ); //Get Resource ID for plugin preference
- if (theIDHandle != NULL)
- mPreferenceRsrcID = **theIDHandle;
- else
- mPreferenceRsrcID = 3500;
- }
-
- }
-
- // ---------------------------------------------------------------------------
- // • ~CEditorWindow
- // ---------------------------------------------------------------------------
- CEditorWindow::~CEditorWindow()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • DoEdit
- //
- // Opens the editor window and handles all editing actions. Returns
- // a value indicating how the user finished the editing task
- //
- // ---------------------------------------------------------------------------
- SInt32 CEditorWindow::DoEdit()
- {
-
- SInt32 theResult = -1;
- LWindow* theDialog = GetDialog();
-
- this->LoadWindowFromFile();
-
- theDialog->Show();
-
- // Set active field
- LEditField* theField = (LEditField*) mDialog->FindPaneByID(kPanelTitleET);
- SignalIf_(theField == nil);
- mDialog->SetLatentSub(theField);
-
-
- while (true) {
- MessageT hitMessage = DoDialog();
-
- if (hitMessage == msg_Cancel) { // Cancel button
- theResult = 1;
- break;
-
- } else if (hitMessage == msg_OK) { // OK button
- this->SaveWindowToFile();
- theResult = 0;
- break;
-
- } else if (hitMessage == kRemoveB) { // Remove button
- theResult = 2;
- break;
-
- } else if (hitMessage == kEditMainTextB) { // Edit main text
- DoEditText( mFileRefNum, mMainTextRsrcID );
-
- } else if (hitMessage == kEditHelpTextB) { // Edit help text
-
- if( mDialog->FindPaneByID(kEmbedHelpTextRB)->GetValue() )
- DoEditText( mFileRefNum, mHelpTextRsrcID );
- else
- DoEditFileRef( mFileRefNum, mHelpTextRsrcID );
-
- } else if (hitMessage == kEditAppFileRefB) { // Edit application location
- DoEditFileRef( mFileRefNum, mAppFileRefRsrcID );
-
- } else { // Idle time tasks
-
- if( mDialog->FindPaneByID(kEmbedHelpTextRB)->GetValue() )
- mDialog->FindPaneByID(kFirstHelpPicET)->Enable();
- else
- mDialog->FindPaneByID(kFirstHelpPicET)->Disable();
-
- }
- }
-
- return theResult;
- }
-
-
- // ---------------------------------------------------------------------------
- // • SaveWindowToFile
- //
- // Writes the contents of the window out to the plug-in's preference
- // resource.
- //
- // ---------------------------------------------------------------------------
- void CEditorWindow::SaveWindowToFile()
- {
- SInt16 savedResFile = CurResFile();
- UseResFile( mFileRefNum );
-
- TRsrcHandle* theRsrcStream = new TRsrcHandle();
- SignalIf_(theRsrcStream == nil);
-
- if( mStringListRsrcID == 0 )
- mStringListRsrcID = GetUniqueIDForResType( mFileRefNum, 'STR#' );
-
- theRsrcStream->AppendShort( 0 ); // Append Format
-
- // Help Text flag
- LStdRadioButton* theRadioButton = (LStdRadioButton*) mDialog->FindPaneByID(kEmbedHelpTextRB);
- SignalIf_(theRadioButton == nil);
- if( theRadioButton->GetValue() )
- mFlags &= ~kHelpTextInFile;
- else
- mFlags |= kHelpTextInFile;
-
-
- theRsrcStream->AppendShort( mFlags );
- theRsrcStream->AppendShort( mMainTextRsrcID );
- theRsrcStream->AppendShort( mHelpTextRsrcID );
-
-
- // First Help pict value
- LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFirstHelpPicET);
- SignalIf_(theField == nil);
- SInt16 theHelpFirstPictRsrcID = theField->GetValue();
- theRsrcStream->AppendShort( theHelpFirstPictRsrcID );
-
- // Panel name
- theField = (LEditField*) mDialog->FindPaneByID(kPanelTitleET);
- SignalIf_(theField == nil);
- Str255 theStr;
- theField->GetDescriptor( theStr );
- WriteStringListResourceIndex( mFileRefNum, theStr, mStringListRsrcID, 1 );
- theRsrcStream->AppendShort( mStringListRsrcID );
-
- // Help window title string
- UseResFile( savedResFile );
- GetIndString( theStr, 233, 2 );
- UseResFile( mFileRefNum );
-
- WriteStringListResourceIndex( mFileRefNum, theStr, mStringListRsrcID, 2 );
-
-
- // App File Ref
- theRsrcStream->AppendShort( mAppFileRefRsrcID );
-
-
- // Build Res list resource
- ResetResListResource( mFileRefNum, mResListRsrcID );
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'sapr', mPreferenceRsrcID );
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'STR#', mStringListRsrcID );
-
- if( mFlags & kHelpTextInFile ) {
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'flrf', mHelpTextRsrcID );
- } else {
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'TEXT', mHelpTextRsrcID );
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'styl', mHelpTextRsrcID );
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'PICT', theHelpFirstPictRsrcID );
- }
-
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'TEXT', mMainTextRsrcID );
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'styl', mMainTextRsrcID );
-
-
- AppendToResListResource( mFileRefNum, mResListRsrcID, 'flrf', mAppFileRefRsrcID );
-
- theRsrcStream->Write( mFileRefNum, 'sapr', mPreferenceRsrcID );
-
-
- delete theRsrcStream;
-
- UseResFile( savedResFile );
- }
-
-
- // ---------------------------------------------------------------------------
- // • LoadWindowFromFile
- //
- // Reads plug-in's preference resource and fills in fields of editor window.
- // If the resource hasn't been created yet, then routine provides default
- // values for the fields.
- //
- // ---------------------------------------------------------------------------
- void CEditorWindow::LoadWindowFromFile()
- {
-
- SInt16 savedResFile = CurResFile();
- UseResFile( mFileRefNum );
-
- Handle theRsrcHandle = Get1Resource( 'sapr', mPreferenceRsrcID );
-
- if( theRsrcHandle )
- {
- TRsrcHandle* theRsrcStream = new TRsrcHandle( theRsrcHandle );
- SignalIf_(theRsrcStream == nil);
-
- if( theRsrcStream->ReadShort() == 0)
- {
-
- mFlags = theRsrcStream->ReadShort();
-
- // Set Embedded Help Text Radio Button
- LStdRadioButton* theRadioButton = (LStdRadioButton*) mDialog->FindPaneByID(kEmbedHelpTextRB);
- SignalIf_(theRadioButton == nil);
- theRadioButton->SetValue( (mFlags & kHelpTextInFile) != kHelpTextInFile );
-
- // Set File Help Text Radio Button
- theRadioButton = (LStdRadioButton*) mDialog->FindPaneByID(kFileHelpTextRB);
- SignalIf_(theRadioButton == nil);
- theRadioButton->SetValue( (mFlags & kHelpTextInFile) == kHelpTextInFile );
-
- mMainTextRsrcID = theRsrcStream->ReadShort();
- mHelpTextRsrcID = theRsrcStream->ReadShort();
-
- // Set First Help pict value
- LEditField* theField = (LEditField*) mDialog->FindPaneByID(kFirstHelpPicET);
- SignalIf_(theField == nil);
- theField->SetValue( theRsrcStream->ReadShort() );
-
- // Set Panel name
- theField = (LEditField*) mDialog->FindPaneByID(kPanelTitleET);
- SignalIf_(theField == nil);
- mStringListRsrcID = theRsrcStream->ReadShort();
- Str255 thePanelTitleStr;
- GetIndString( thePanelTitleStr, mStringListRsrcID, 1 );
- theField->SetDescriptor( thePanelTitleStr );
-
-
- // App File Ref
- mAppFileRefRsrcID = theRsrcStream->ReadShort();
-
- }
-
- delete theRsrcStream;
-
- } else {
- mFlags = 0;
- mStringListRsrcID = 0;
- mMainTextRsrcID = 0;
- mHelpTextRsrcID = 0;
- mAppFileRefRsrcID = 0;
- }
-
- UseResFile( savedResFile );
- }
-
-
-
-